/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package muticastserver;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
/**
 *
 * @author Minh
 */
public class MutiCastServer {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
         MulticastSocket socket = null;
        DatagramPacket inPacket = null;
        byte[] inBuf = new byte[1024];
        try
        {
          //Prepare to join multicast group
          socket = new MulticastSocket(1234);
          InetAddress address = InetAddress.getByName("225.4.5.6");
          socket.joinGroup(address);

              while(true)
              {
                    System.out.println("Listening");
                    inPacket = new DatagramPacket(inBuf, inBuf.length);
                    socket.receive(inPacket);
                    String msg = new String(inBuf, 0, inPacket.getLength());
                    System.out.println("From :" + inPacket.getAddress() + " Msg : " + msg);
              }
        }
        catch(Exception ioe)
        {
            System.out.println(ioe);
        }
    }
}
